//给你一个整数数组 nums，有一个大小为 k 的滑动窗口从数组的最左侧移动到数组的最右侧。你只可以看到在滑动窗口内的 k 个数字。滑动窗口每次只向右移动一位
//。 
//
// 返回 滑动窗口中的最大值 。 
//
// 
//
// 示例 1： 
//
// 
//输入：nums = [1,3,-1,-3,5,3,6,7], k = 3
//输出：[3,3,5,5,6,7]
//解释：
//滑动窗口的位置                最大值
//---------------               -----
//[1  3  -1] -3  5  3  6  7       3
// 1 [3  -1  -3] 5  3  6  7       3
// 1  3 [-1  -3  5] 3  6  7       5
// 1  3  -1 [-3  5  3] 6  7       5
// 1  3  -1  -3 [5  3  6] 7       6
// 1  3  -1  -3  5 [3  6  7]      7
// 
//
// 示例 2： 
//
// 
//输入：nums = [1], k = 1
//输出：[1]
// 
//
// 
//
// 提示： 
//
// 
// 1 <= nums.length <= 10⁵ 
// -10⁴ <= nums[i] <= 10⁴ 
// 1 <= k <= nums.length 
// 
// Related Topics 队列 数组 滑动窗口 单调队列 堆（优先队列） 👍 1494 👎 0

package leetcode.editor.cn;

import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

public class _239_SlidingWindowMaximum {
    public static void main(String[] args) {
        Solution solution = new _239_SlidingWindowMaximum().new Solution();
        int[] nums = new int[] {1,3,-1,-3,5,3,6,7};

        method(nums);

        int k = 3;
        int[] res = solution.maxSlidingWindow(nums, k);
        System.out.println(Arrays.toString(res));
    }

    private static void method(int[] nums) {
        System.out.println("Test the comparator implement:");
        Arrays.sort(nums);
        System.out.println(Arrays.toString(nums));
    }


    class Solution {
        public int[] maxSlidingWindow(int[] nums, int k) {
            int n = nums.length;
            PriorityQueue<int[]> pq = new PriorityQueue<>(new Comparator<int[]>() {
                @Override
                public int compare(int[] o1, int[] o2) {
                    return 0;
                }
            });
            return null;
        }
    }

/*
    class Soultion {
        public int[] maxSlidingWindow(int[] nums, int k) {
            int[][] numsIndex = new int[nums.length][2];
            for (int i = 0; i < nums.length; i++) {
                numsIndex[i][0] = nums[i];
                numsIndex[i][1] = i;
            }
            int[] res = new int[nums.length + 1 - k];
            for (int i = 0; i < k; i++) {
                heapInsert(numsIndex, i);
            }
            int heapSize = k;
            res[0] = numsIndex[0][0];
            for (int i = k; i < nums.length; i++) {
                heapInsert(numsIndex, i);
                while (numsIndex[i][1] <= i - k) {

                }

            }
        }

        private void heapify(int[][] nums, int index, int heapSize) {
            int left = 2 * index + 1;
            while (left < heapSize) {
                int largestIndex = left + 1 < heapSize && nums[left+1][0] > nums[left][0] ? left+1 : left;
                largestIndex = nums[largestIndex][0] > nums[index][0] ? largestIndex : index;

                if (largestIndex == index) break;

                swap(nums, index, largestIndex);

                index = largestIndex;
                left = 2 * index + 1;
            }
        }

        private void heapInsert(int[][] nums, int index) {
            while (nums[index][0] > nums[(index - 1) / 2][0]) {
                swap(nums, index, (index - 1) / 2);
                index = (index - 1) / 2;
            }
        }

        private void swap(int[][] nums, int a, int b) {
            int tmp = nums[a][0];
            nums[a][0] = nums[b][0];
            nums[b][0] = tmp;

            tmp = nums[a][1];
            nums[a][1] = nums[b][1];
            nums[b][1] = tmp;
        }
    }
*/


    //leetcode submit region begin(Prohibit modification and deletion)
    // 超时了
    class Solution1 {
        public int[] maxSlidingWindow(int[] nums, int k) {
            int[] res = new int[nums.length - k + 1];
            for (int i = 0; i < res.length; i++) {
                res[i] = process(nums, i, k);
            }
            return res;
        }

        private int process(int[] nums, int start, int k) {
            int max = nums[start];
            for (int i = 1; i < k; i++) {
                max = Math.max(max, nums[start + i]);
            }
            return max;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}